<template>
  <div class="news-container">
    <!-- 上部分：新闻头部区域 -->
    <div class="news-header">
      <div class="news-banner">
        <h1 class="news-title">最新动态</h1>
        <p class="news-subtitle">了解我们的最新消息、活动和公告</p>
      </div>
      <div class="news-categories">
        <div v-for="(news,index) in newsList" :key="index">
          <!-- router query 第一种传参方式 -->
          <!-- <RouterLink class="nav-text" :to="`/news/detail?title=${news.title }&content=${ news.content }&date=${ news.date }`">{{news.title}}</RouterLink> -->
          <!-- router query 第二种传参方式 -->
          <!-- <RouterLink class="nav-text" 
            :to="{path:'/news/detail',
            query:{title:news.title,content:news.content,date:news.date}}">
            {{news.title}}</RouterLink> -->

            <!-- router params 传参 可以直接在路径上写参数，但是需要在router.ts中对应的路由上提前占位-->
            <!-- 例如  path: 'detail/:title/:content/:date' -->
             <!-- 第一种写法 -->
             <!-- <RouterLink class="nav-text" :to="`/news/detail/${news.title}/${news.content}/${ news.date}`">{{news.title}}</RouterLink> -->
            <!-- 第二种写法 -->
             <!-- 需要注意的是这样写，不可以传path，而是要传路由名称 -->
             <!-- <RouterLink class="nav-text" 
             :to="{name:'新闻详情',
             params:{title:news.title,content:news.content,date:news.date}}"
             >{{news.title}}
             </RouterLink> -->

             <!-- 第二种写法 -->
             <!-- 需要注意的是这样写，不可以传path，而是要传路由名称 -->
            <button class="nav-text" @click="showDetail(news)">查看新闻</button>
        </div>  
      </div>
      <div class="news-content">
          <RouterView></RouterView>
        </div>
    </div>
 </div>
  
</template>

<script lang="ts" setup>
import { ref, computed } from 'vue';
import {RouterLink, RouterView,useRouter} from 'vue-router';
import detail from '@/views/news/detail/index.vue'

const router = useRouter()
const newsList = ref([
  {
    id: 1,
    title: '最新活动',
    content: '参加我们的最新活动，了解更多信息。',
    date: '2023-10-01', 
  },
  {
    id: 2,
    title: '公告通知',
    content: '请关注我们的重要公告，了解最新信息。',
    date: '2023-10-02', 
  },
  {
    id: 3,
    title: '新闻报道',
    content: '了解我们的最新新闻报道，了解更多信息。',
    date: '2023-10-03', 
  }
])
function showDetail(news:any){
  console.log(news)
  router.push({name:'新闻详情',query:{title:news.title,content:news.content,date:news.date}})
}
</script>

<style scoped>
/* 全局样式 */
.news-container {
  max-width: 100%;
  margin: 0 auto;
  color: #333;
  font-family: 'Helvetica Neue', Arial, sans-serif;
}

/* 新闻头部区域 */
.news-header {
  margin-bottom: 30px;
}

.news-banner {
  background: linear-gradient(to right, #64b3f4, #c2e59c);
  padding: 40px;
  border-radius: 12px;
  color: white;
  text-align: center;
  margin-bottom: 20px;
}

.news-title {
  font-size: 32px;
  font-weight: 500;
  margin-bottom: 10px;
  letter-spacing: 1px;
}

.news-subtitle {
  font-size: 16px;
  opacity: 0.9;
}

.news-categories {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-top: 20px;
}

.category-item {
  padding: 8px 16px;
  background-color: #f5f7fa;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid #eee;
}

.category-item:hover {
  background-color: #e8f4ff;
  border-color: #64b3f4;
}

.category-item.active {
  background-color: #64b3f4;
  color: white;
  border-color: #64b3f4;
}

/* 新闻内容区域 */
.news-content {
  display: flex;
  gap: 30px;
}

/* 左侧新闻列表 */
.news-list {
  width: 40%;
  max-height: 700px;
  overflow-y: auto;
  padding-right: 15px;
}

.news-item {
  display: flex;
  margin-bottom: 20px;
  padding: 15px;
  border-radius: 10px;
  background-color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid #eee;
}

.news-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  border-color: #ddd;
}

.news-item.active {
  border-left: 4px solid #64b3f4;
  background-color: #f8fbff;
}

.news-item-date {
  min-width: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-right: 15px;
}

.date-day {
  font-size: 24px;
  font-weight: 500;
  color: #64b3f4;
}

.date-month {
  font-size: 14px;
  color: #888;
}

.news-item-content {
  flex: 1;
}

.news-item-title {
  font-size: 16px;
  margin-bottom: 8px;
  color: #333;
  line-height: 1.4;
}

.news-item-summary {
  font-size: 14px;
  color: #666;
  margin-bottom: 10px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.news-item-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

.news-category-tag {
  color: #64b3f4;
  background-color: rgba(100, 179, 244, 0.1);
  padding: 2px 8px;
  border-radius: 10px;
}

.news-read-time {
  color: #888;
}

/* 右侧新闻详情 */
.news-detail {
  flex: 1;
  background-color: white;
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 2px 15px rgba(0, 0, 0, 0.05);
}

.news-detail-header {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid #eee;
}

.detail-title {
  font-size: 24px;
  color: #333;
  margin-bottom: 15px;
  line-height: 1.4;
}

.detail-meta {
  display: flex;
  gap: 20px;
  color: #888;
  font-size: 14px;
}

.detail-cover {
  margin-bottom: 25px;
  border-radius: 10px;
  overflow: hidden;
}

.detail-cover img {
  width: 100%;
  height: auto;
  object-fit: cover;
}

.detail-content {
  line-height: 1.8;
  color: #444;
  font-size: 16px;
}

.detail-content p {
  margin-bottom: 15px;
}

.detail-content ul, .detail-content ol {
  margin-bottom: 15px;
  padding-left: 20px;
}

.detail-content li {
  margin-bottom: 8px;
}

.detail-actions {
  display: flex;
  gap: 20px;
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.action-button {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 15px;
  border-radius: 20px;
  background-color: #f5f7fa;
  cursor: pointer;
  transition: all 0.3s ease;
}

.action-button:hover {
  background-color: #e8f4ff;
  color: #64b3f4;
}

/* 右侧占位提示 */
.news-detail-placeholder {
  flex: 1;
  background-color: white;
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 2px 15px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 400px;
}

.placeholder-icon {
  font-size: 48px;
  margin-bottom: 20px;
  color: #ccc;
}

.news-detail-placeholder h3 {
  font-size: 20px;
  color: #333;
  margin-bottom: 10px;
}

.news-detail-placeholder p {
  color: #888;
}

/* 滚动条样式 */
.news-list::-webkit-scrollbar {
  width: 6px;
}

.news-list::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.news-list::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.news-list::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

.news-content {
  width: 100%;
  height: 500px;
  gap: 30px; 
  padding: 4%;
}

/* 响应式调整 */
@media (max-width: 992px) {
  .news-content {
    flex-direction: column;
  }
  
  .news-list {
    width: 100%;
    max-height: none;
    padding-right: 0;
  }
}
</style>